<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>短信发送管理</title>
	<meta name="decorator" content="default"/>
	<script src="assets/js/jquery.js"></script>
	<script src="${ctxStatic}/docheck/docheck.js" type="text/javascript"></script>
	<script type="text/javascript">
        $(document).ready(function() {

        });
        function page(n,s){
            $("#pageNo").val(n);
            $("#pageSize").val(s);
            $("#searchForm").submit();
            return false;
        }

        function showTestModal(smsContent){
            $('#smsSendContent').val(smsContent);
            $('#smsContentSize').text(smsContent.length);
            $('#smsContentModal').modal('show');
        }
        //通知 0 设置成功 1设置失败
        function checkSendStatus(type,sendStatus){
            var ids = getCheckboxValue("id");
            if(ids==""){
                alert("请选择要处理的记录");
            }else {
                setSendStatus(ids, type, sendStatus);
            }
        }
        //查看明细
        function onSendView(id){
            var url = "${ctx}/sms/smsSend/smsSendListCheckMore?id="+id;
            windowOpen(url,id,800,450);
        }
        //通知 0 设置成功 1设置失败
        function setSendStatus(id, type,sendStatus){
            var actionUrl = "${ctx}/sms/smsSend/setSendStatusJudge?ids=" + id + "&type=" + type + "&sendStatus=" + sendStatus;
            var status = "审核成功"
            if (sendStatus.indexOf("F")!=-1) {
                status = "审核失败"
            }
            top.$.jBox.confirm("确认设置状态为"+status+"吗？选择是，不同短信内容直接下发，同内容可修改短信内容，选择否，取消修改","系统提示",function(v,h,f) {
                if (v == "ok") {
                	if (status=="审核成功"){
						$.ajax({
								   url: actionUrl,
								   success: function (data) {
									   page();
									   if (data=="不合法"){
										   var actionUrl2 = "${ctx}/sms/smsSend/setSendStatus?ids=" + id + "&type=" + type + "&sendStatus=" + sendStatus;
										   var pass=confirm("你批量选择的号码中内容不一致,点击确认将会直接审核通过。")
										   if (pass){
											   $.ajax({
														  url:actionUrl2,
														  success:function(data2){
															  alert(data2);
															  page();
														  }, error: function () {
													   alert("设置失败");
												   }, dataType: "text",
														  timeout:20000
													  })
										   }
									   }else if(data=="合法"){//去编辑页面
										   var url="${ctx}/sms/smsSend/batchCheckForm?ids=" + id + "&type=" + type + "&sendStatus=" + sendStatus;
										   location.href=url;
										   return false;

									   }else{
										   alert("你选择的号码中有已经失效的，请刷新页面再试");
									   }
								   },
								   error: function () {
									   alert("设置失败");
								   },
								   dataType: "text",
								   timeout:20000
							   });
					}else{//批量设置失败
						var actionUrl2 = "${ctx}/sms/smsSend/setSendStatus?ids=" + id + "&type=" + type + "&sendStatus=" + sendStatus;
						$.ajax({
								   url:actionUrl2,
								   success:function(data2){
									   alert(data2);
									   page();
								   }, error: function () {
								alert("设置失败");
							}, dataType: "text",
								   timeout:20000
							   })
					}

                }
            },{buttonsFocus:1});
            top.$('.jbox-body .jbox-icon').css('top','55px');
        }
	</script>
</head>
<body>
<ul class="nav nav-tabs">
	<li class="active"><a href="${ctx}/sms/smsSend/list?sendStatus=V">提单审核</a></li>
	<!--<shiro:hasPermission name="sms:smsSend:edit"><li><a href="${ctx}/sms/smsSend/form">短信发送添加</a></li></shiro:hasPermission>-->
</ul>
<form:form id="searchForm" modelAttribute="smsSend" action="${ctx}/sms/smsSend/check" method="post" class="breadcrumb form-search">
	<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
	<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
	<input id="isEffective" name="isEffective" type="hidden" value="1"/>
	<input id="sendStatus" name="sendStatus" type="hidden" value="V"/>
		<li><label>内容查询：</label>
			<form:textarea path="smsContent" rows="3" cols="11" htmlEscape="false" class="input-medium"/>
		</li>
		<li><label>手机号码：</label>
			<form:input path="phoneFind" htmlEscape="false" maxlength="32" class="input-medium"/>
		</li>
		<li><label>提单号：</label>
			<form:input path="taskid" htmlEscape="false"  class="input-medium"/>
		</li>
		<li><label>是否批量：</label>
			<form:select path="showLevel" class="input-medium">
				<form:option value="" label="全部"/>
				<form:options items="${fns:getDictList('showLevel')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
			</form:select>
		</li>
		<li><label>发送时间：</label>
			<input name="sendTimeQ" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate"
				   value="<fmt:formatDate value="${smsSend.sendTimeQ}" pattern="yyyy-MM-dd HH:mm:ss"/>"
				   onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false});"/>
		</li>
		<li><label>本页号码数：</label>
			<form:input path="count" htmlEscape="false"  class="input-medium" value="${count}"/>
		</li>
		<li class="btns"><input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/></li>
	<ul class="ul-form">
			<li class="btns"><input id="checkSuccSubmit" type="button" class="btn btn-primary" value="审核通过" onclick="javasrcipt:checkSendStatus(1,'TOOO');" /></li>
			<li class="btns"><input id="checkFailSubmit" type="button" class="btn btn-primary" value="审核不通过" onclick="javasrcipt:checkSendStatus(1,'FOO1');" /></li>
			<li class="clearfix"></li>
		<!--
		<li class="btns"><input id="sendSuccSubmit" class="btn btn-primary" type="submit" value="发送成功" onclick="javasrcipt:checkSendStatus(1,'TOOO');" /></li>
		<li class="btns"><input id="sendFailSubmit" class="btn btn-primary" type="submit" value="发送失败" onclick="javasrcipt:checkSendStatus(1,'FOO1');" /></li>
		<li class="btns"><input id="againSubmit" class="btn btn-primary" type="submit" value="重新提交网关" onclick="javasrcipt:checkSendStatus(1,'FOO1');" /></li>
		-->
	</ul>
</form:form>
<sys:message content="${message}"/>
<table id="contentTable" class="table table-striped table-bordered table-condensed">
	<thead>
	<tr>
		<th><input type="checkbox" onclick="doCheckAll(this,'id', this.checked)"></th>
		<th>提交时间</th>
		<shiro:hasPermission name="sms:smsSend:devloper">
			<th>提单号</th>
		</shiro:hasPermission>
		<th>定时时间</th>
		<th>公司名称</th>
		<th>账户名称</th>
		<th>短信内容　　　　　　　　　　　　　　　　</th>
		<th>计数</th>
		<th>发送状态</th>
		<th>审核原因</th>
		<th>网关组</th>
		<th>通道</th>
		<shiro:hasPermission name="sms:smsSend:edit"><th>操作</th></shiro:hasPermission>
	</tr>
	</thead>
	<tbody>
	<c:forEach items="${page.list}" var="smsSend">
		<tr onclick="selectTr(this, '${smsSend.id}' ,'id')">
			<td><input type="checkbox" name="id" id="${smsSend.id}" value="${smsSend.id}" onclick="if(this.checked){this.checked=false;}else{this.checked=true;}"></td>
			<td>
				<fmt:formatDate value="${smsSend.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
			</td>
			<shiro:hasPermission name="sms:smsSend:devloper">
				<td>
					${smsSend.taskid}
				</td>
			</shiro:hasPermission>
			<td>
				<c:if test="${smsSend.sendTime != null}">
					<fmt:formatDate value="${smsSend.sendTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
				</c:if>
			</td>
			<td>
				<a href="javascript:onSendView('${smsSend.id}')">
						${fns:getUserById(smsSend.userid).companyShortname}|
						${fns:getUserById(smsSend.userid).loginName}
					</a>
			</td>
			<td>
					${fns:getUserById(smsSend.userid).loginName} | ${fns:getDictLabel(smsSend.smsType, 'service_id', smsSend.smsType)}
			</td>
			<td>
					${fn:substring(smsSend.smsContent, 0, 20)}...
				<a href="javascript:showTestModal('${fns:escapeHtml(smsSend.smsContent)}')">[更多查看]</a>
			</td>
			<td>
					${smsSend.smsSize}
			</td>
			<td>
					${fns:getDictLabel(smsSend.sendStatus, 'sendStatus', smsSend.sendStatus)}
					<%--${fns:startsWith(smsSend.sendStatus,'T') ? '发送成功' : '发送失败'}--%>
			</td>
			<td>
					${smsSend.checkReason}
			</td>
			<td>
					${smsSend.gatewayGroup}
			</td>
			<td>
					${smsSend.gatewayId}
			</td>
			<!--
			<td>
				<c:choose>
					<c:when test="${fn:length(smsSend.phone) > 23}">
						${fn:substring(smsSend.phone, 0, 24)}...
						<a href="javascript:showTestModal('${fns:escapeHtml(smsSend.phone)}')">[更多查看]</a>
						[<fmt:parseNumber integerOnly="true" value="${(fn:length(smsSend.phone)+1)/12}" />个]
					</c:when>
					<c:otherwise>
						${smsSend.phone}
					</c:otherwise>
				</c:choose>
			</td>
			-->
			<shiro:hasPermission name="sms:smsSend:edit"><td>
				<a href="${ctx}/sms/smsSend/formCheck?id=${smsSend.id}">审核修改</a>
				<a href="javascript:setSendStatus('${smsSend.id}',1,'F001')">审核失败</a>
			</td></shiro:hasPermission>
				<%--<shiro:hasPermission name="sms:smsSend:edit"><td>--%>
				<%--<c:set var="status" value="${smsSend.sendStatus}"/>--%>
				<%--<c:if test="${fn:contains(status,'V')}">--%>
				<%--<a href="javascript:setSendStatus('${smsSend.id}',1,'T000')">审核通过</a>--%>
				<%--<a href="javascript:setSendStatus('${smsSend.id}',1,'F001')">审核失败</a>--%>
				<%--</c:if>--%>
				<%--&lt;%&ndash;<a href="javascript:windowOpen('${debug}/cache.jsp?type=1&key=${smsGateway.gwCode}','网关信息',900,550);">调试</a>&ndash;%&gt;--%>
				<%--<!-- <a href="${ctx}/sms/smsGateway/delete?id=${smsGateway.id}" onclick="return confirmx('确认要删除该通道信息吗？', this.href)">删除</a> -->--%>
				<%--</td></shiro:hasPermission>--%>
		</tr>
	</c:forEach>
	</tbody>
</table>
<div class="pagination">${page}</div>

<!-- 短信内容 -->
<div class="modal fade" style="display:none;" id="smsContentModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close"
						data-dismiss="modal" aria-hidden="true">
					&times;
				</button>
				<h4 class="modal-title" id="myModalLabel">
					短信内容
				</h4>
			</div>
			<div class="modal-body">
				<form id="gateWaySendForm" class="form-horizontal">
					<div class="control-group">
						<div class="controls1">
							<textarea style="width:498px;" readonly="readonly" name="smsSendContent" id="smsSendContent" rows="6" cols="8"></textarea>
							共 <label name="smsContentSize" id="smsContentSize"></label>  个字。
						</div>
					</div>
				</form>
			</div>
		</div><!-- /.modal-content -->
	</div><!-- /.modal -->
</div>
<!-- END -->

</body>
</html>